package com.zhangtai.utils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.RedisTemplate;

import java.util.Random;
import java.util.UUID;

@Configuration
public class RedisIdWorker {
    @Autowired
    private RedisTemplate redisTemplate;

    /**
     * 自定义id种类，需要的话自己添加
     */
    public static final String contractId="contractId";  //合同专用id
    public static final String commonId="commonId"; //通用id

    /**
     * 返回Long类型id  1
     * @param key
     * @return
     * @throws Exception
     */
    public Long getLongId(String key){

        Long increment = redisTemplate.opsForHash().increment("redisId",key, 1);

        return increment;

    }

    /**
     * 返回补位 00000001 8位数
     * @param key
     * @return
     * @throws Exception
     */
    public String getStringId(String key) {
        Long longId = getLongId(key);
        String format = String.format("%08d", longId);
        return format;
    }


}
